<!--
 * @FilePath     : /study_code/layui/15-13.html
 * @Description  : remoteSearch 是否开启自定义搜索
 * @Date         : 2025-04-09 15:50:51
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-09 16:09:38
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="demo1" class="xm-select-demo"></div>

    <script src="/xm-select/dist/xm-select.js"></script>
    <script>
      var demo1 = xmSelect.render({
        el: '.xm-select-demo',

        // 初始数据
        /* data: [
          { name: '张三', value: 1 },
          { name: '李四', value: 2 },
          { name: '王五', value: 3 },
        ], */
        data: [],

        // 1、需要先开启搜索；
        filterable: true,
        // 2、开启自定义搜索；
        remoteSearch: true,
        // 3、重写搜索回调；
        remoteMethod: function (val, cb, show, pageIndex) {
          console.log(1, '参数1：val', val)
          console.log(2, '参数2：cb', cb)
          console.log(3, '参数3：show', show)
          console.log(4, '参数4：pageIndex', pageIndex)

          // 这里模拟 3s 后返回数据
          setTimeout(function () {
            // 需要回传一个数组
            cb([
              { name: '水果' + val, value: val + 1 },
              { name: '蔬菜' + val, value: val + 1 },
              { name: '桌子' + val, value: val + 1 },
              { name: '北京' + val, value: val + 1 },
            ])
          }, 3000)
        },
      })
    </script>
  </body>
</html>
